﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Rapid.Entity.Basic;
using Rapid.MvcExtension.Controls.Manage;
using Rapid.WebNecessary;

namespace Rapid.MvcExtension.Controllers
{
    [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]
    public class ManageController : Controller
    {
        /// <summary>
        /// 权限判断
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!SessionFactory.ManageAuthenticated)
            {
                if (filterContext.ActionDescriptor.GetCustomAttributes(typeof(AllowAnonymousAttribute), false).Length == 0)
                {
                    filterContext.Result = LoginContent(); return;
                }
            }

            base.OnActionExecuting(filterContext);
        }

        /// <summary>
        /// 转到登陆
        /// </summary>
        protected ActionResult LoginContent()
        {
            return Content("<script type=\"text/javascript\">location.href=\"/manage/authorize/login\";</script>");
        }
    }
}